package com.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Tools2 {
	public static void main(String[] args) {
		String s = "Java now has regular expressions";

		String[] ss = new String[9];
		ss[0] = "^Java";
		ss[1] = "\\breg.*";// \b代表字与字中间那个看不见的东西，here is a word，那么，这句中有好几个\b,
							// 每个单词的前后都有一个\b
		ss[2] = "n.w\\s+h(a|i)s";// \s空白符（空格、tab、换行、换页和回车）
		ss[3] = "s?";
		ss[4] = "s*";
		ss[5] = "s+";
		ss[6] = "s{4}";
		ss[7] = "s{0}";
		ss[8] = "s{1,3}";
		for (String arg : ss) {
			System.out.println("Regular expression: \"" + arg + "\"");
			Pattern p = Pattern.compile(arg);
			Matcher m = p.matcher(s);
			while (m.find()) {
				System.out.println("Match \"" + m.group() + "\" at positions "
						+ m.start() + "-" + (m.end() - 1));
			}
		}
	}

}
